import numpy as np import cv2 from skimage.transform import radon import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation, PillowWriter # Load and resize the image image_path = '_58f4b8e1-9f7c-4ab7-85c5-6cdf5deea15e.jpeg' image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) image_small = cv2.resize(image, (1920, 1920)) # Resize to 1080p # Create a figure for the plot fig, axs = plt.subplots(1, 2) # Initialize the plot with the first frame axs[0].imshow(image_small, cmap='gray') line, = axs[0].plot([960, 960], [0, 1079], color='red') # Compute the full radon transformation theta = np.linspace(0., 180., 180, endpoint=False) image_radon = radon(image_small, theta=theta) im = axs[1].imshow(image_radon, cmap='gray', aspect='auto') line_radon, = axs[1].plot([0, 0], [0, image_radon.shape[0]], color='red') def update(i): # Update the red line in the original image x = 960 + 960 * np.cos(np.deg2rad(i+90)) y = 960 + 960 * np.sin(np.deg2rad(i+90)) line.set_data([1920-x, x], [1920-y, y]) # Update the red line in the radon transformation image line_radon.set_data([i, i], [0, image_radon.shape[0]]) # Create an animation ani = FuncAnimation(fig, update, frames=np.arange(0, 180, 1)) # Save the animation as a GIF gif_path = 'radon_transform.gif' # replace with your preferred path ani.save(gif_path, writer=PillowWriter(fps=60)) # Increase FPS to 60